package com.bysj.studentsystem.controller;

import com.bysj.studentsystem.vo.ResponseDataVO;
import com.bysj.studentsystem.entity.SysRewardAssistedLoan;
import com.bysj.studentsystem.service.SysRewardAssistedLoanService;
import com.bysj.studentsystem.vo.SysRewardAssistedLoanVO;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (SysRewardAssistedLoan)奖助贷管理控制层
 *
 * @author makejava
 * @since 2024-03-09 16:51:49
 */
@RestController
@RequestMapping("reward/assisted/loan")
public class SysRewardAssistedLoanController {
    /**
     * 服务对象
     */
    @Resource
    private SysRewardAssistedLoanService sysRewardAssistedLoanService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @GetMapping
    public ResponseDataVO<PageInfo<SysRewardAssistedLoanVO>> queryByPage(@RequestParam(value = "id", required = false) Integer id,
                                                                         @RequestParam(value = "title", required = false) String title,
                                                                         @RequestParam(value = "content", required = false) String content,
                                                                         @RequestParam(value = "applyId", required = false) Integer applyId,
                                                                         @RequestParam(value = "pageNum", required = false) Integer pageNum,
                                                                         @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        if (pageNum == null || pageSize == null) {
            pageNum = 1;
            pageSize = 10;
        }
        SysRewardAssistedLoan sysRewardAssistedLoan = new SysRewardAssistedLoan();
        sysRewardAssistedLoan.setId(id);
        sysRewardAssistedLoan.setTitle(title);
        sysRewardAssistedLoan.setContent(content);
        sysRewardAssistedLoan.setApplyId(applyId);
        return new ResponseDataVO().ok(this.sysRewardAssistedLoanService.queryByPage(sysRewardAssistedLoan, pageNum, pageSize));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseDataVO<SysRewardAssistedLoan> queryById(@PathVariable("id") Integer id) {
        return new ResponseDataVO().ok(this.sysRewardAssistedLoanService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param sysRewardAssistedLoan 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseDataVO<SysRewardAssistedLoan> add(@RequestBody SysRewardAssistedLoan sysRewardAssistedLoan) {
        return new ResponseDataVO().ok(this.sysRewardAssistedLoanService.insert(sysRewardAssistedLoan));
    }

    /**
     * 编辑数据
     *
     * @param sysRewardAssistedLoan 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseDataVO<SysRewardAssistedLoan> edit(@RequestBody SysRewardAssistedLoan sysRewardAssistedLoan) {
        return new ResponseDataVO().ok(this.sysRewardAssistedLoanService.update(sysRewardAssistedLoan));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseDataVO<Boolean> deleteById(@RequestParam("id") Integer id) {
        return new ResponseDataVO().ok(this.sysRewardAssistedLoanService.deleteById(id));
    }

}

